package bt2array

import (
	C "gitee.com/ljfirst/algo-go-sdk/common/constant"
	"gitee.com/ljfirst/algo-go-sdk/src/data_structure/heap_stack_queue/stack"
	"gitee.com/ljfirst/algo-go-sdk/src/data_structure/list"
)

/**
 * @author ljfirst
 * @version V1.0
 * @date 2023/7/22 15:55
 * @author-Email ljfirst@mail.ustc.edu.cn
 * @blogURL https://blog.csdn.net/ljfirst
 * @description
 **/
type InOrderByStack struct {
	ans []int
}

func (m *InOrderByStack) Method(node *list.Node) []int {
	if node == nil {
		return nil
	}
	if len(m.ans) == 0 {
		m.ans = make([]int, 0)
	}
	stackTools := stack.ArrayStack{}
	for !stackTools.Empty() || node != nil {
		for node != nil {
			stackTools.Push(node)
			node = node.Left
		}
		node = stackTools.Pop().(*list.Node)
		m.ans = append(m.ans, node.Value.(int))
		node = node.Right
	}
	return m.ans
}

func (m *InOrderByStack) GetAttribute() *C.Attribute {
	return &C.Attribute{
		Tags: []string{C.Tree, C.InOrder, C.Stack},
		Desc: &C.Desc{
			Name:        "InOrderByStack",
			NameCn:      "",
			Description: "",
			ParamsDesc: map[string]string{
			},
			Example: map[int]string{
			},
		},
	}
}
